#ifndef __ATK_MS901M_UART_H
#define __ATK_MS901M_UART_H

#include "stm32f4xx.h"
#include "misc.h"

/* 引脚定义 */
#define ATK_MS901M_UART_TX_PORT                GPIOC
#define ATK_MS901M_UART_TX_PIN                 GPIO_Pin_12
#define ATK_MS901M_UART_TX_PIN_SOURCE          GPIO_PinSource12
#define ATK_MS901M_UART_TX_AF                  GPIO_AF_UART5

#define ATK_MS901M_UART_RX_PORT                GPIOD
#define ATK_MS901M_UART_RX_PIN                 GPIO_Pin_2
#define ATK_MS901M_UART_RX_PIN_SOURCE          GPIO_PinSource2
#define ATK_MS901M_UART_RX_AF                  GPIO_AF_UART5

#define ATK_MS901M_UART                        UART5
#define ATK_MS901M_UART_IRQn                   UART5_IRQn
#define ATK_MS901M_UART_IRQHandler             UART5_IRQHandler

/* 时钟使能宏 */
#define ATK_MS901M_UART_TX_GPIO_CLK_ENABLE()   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE)
#define ATK_MS901M_UART_RX_GPIO_CLK_ENABLE()   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE)
#define ATK_MS901M_UART_CLK_ENABLE()           RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE)

/* 缓冲大小 */
#define ATK_MS901M_UART_RX_FIFO_BUF_SIZE       128

/* 操作函数 */
uint8_t atk_ms901m_uart_rx_fifo_write(uint8_t *dat, uint16_t len);
uint16_t atk_ms901m_uart_rx_fifo_read(uint8_t *dat, uint16_t len);
void atk_ms901m_rx_fifo_flush(void);
void atk_ms901m_uart_send(uint8_t *dat, uint8_t len);
void atk_ms901m_uart_init(uint32_t baudrate);

#endif 
